package com.manage.service.impl;

import com.manage.dao.IClazzDao;
import com.manage.domain.Clazz;
import com.manage.service.IClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ClazzServiceImpl implements IClazzService {

    @Autowired
    private IClazzDao clazzDao;

    @Override
    public List<Clazz> list() {
        return clazzDao.list();
    }

    @Override
    public void add(Clazz clazz) { clazzDao.insert(clazz); }

    @Override
    public void update(Clazz clazz) { clazzDao.update(clazz); }

    @Override
    public void delete(Integer id) {
        int cnt = clazzDao.countStudents(id);
        if (cnt > 0) {
            throw new IllegalStateException("该班级下存在学员，无法删除");
        }
        clazzDao.deleteById(id);
    }
}


